package com.example.cadmin.security.handler;

import com.example.cadmin.Application;
import com.example.cadmin.entity.LoginLog;
import com.example.cadmin.security.dto.JwtUserDto;
import com.example.cadmin.service.HostService;
import com.example.cadmin.service.LoginLogService;
import com.example.cadmin.utils.DateFormat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 退出回调
 */
@Slf4j
@Component
public class MyLogoutHandler implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        JwtUserDto userDetails = (JwtUserDto)authentication.getPrincipal();//拿到登录用户信息

        //保存登录日志
//        LoginLog loginLog = new LoginLog();
//        loginLog.setUserName(userDetails.getUsername());
//        loginLog.setCreateTime(DateFormat.getTime());
//        loginLog.setType(2);
//
//        LoginLogService loginLogService = Application.ac.getBean(LoginLogService.class);
//        loginLogService.save(loginLog);

    }
}
